%   P. D. Kovesi.   MATLAB and Octave Functions for Computer Vision and Image Processing.
%   Centre for Exploration Targeting
%   School of Earth and Environment 
%   The University of Western Australia. 
%   Available from:
%   <http://www.csse.uwa.edu.au/~pk/research/matlabfns/>. 
% 
% 
% BibTeX entry:
%   @misc {KovesiMATLABCode,
%   author = "P. D. Kovesi",
%   title = "{MATLAB} and {Octave} Functions for Computer Vision and Image Processing",
%   howpublished = "{C}entre for {E}xploration {T}argeting, {S}chool of {E}arth and {E}nvironment,
%                 {T}he {U}niversity of {W}estern {A}ustralia",
%   note = "Available from: $<$http://www.csse.uwa.edu.au/$\sim$pk/research/matlabfns/$>$",
%   }


function [im, tuv] = fingerprint_to_flow_field(imagefile)

im = imread(imagefile);
%im = rgb2gray(im); %convert it to grayscale image
%im = imresize(im,[256 256],'bicubic');%convert it to gray scale
% Identify ridge-like regions and normalise image
blksze = 16; thresh = 0.1;
[normim, mask] = ridgesegment(im, blksze, thresh);
%show(normim,1);
    
% Determine ridge orientations
[orientim, reliability] = ridgeorient(normim, 1, 5, 5);
[u,v] = plotridgeorient(orientim, 20, im, 2);
tuv = cat(3,u,v);
tuv = imresize(tuv,[size(im,1) size(im,2)],'bicubic');


